T
CSharpTest.Net
WorkQueue<T> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Threading Namespace : WorkQueue<T> Class

Glossary Item Box

An extremely basic WorkQueue using a fixed number of threads to execute Action<T> over the enqueued instances of type T, aggregates an instance of WorkQueue()

Syntax

Visual Basic (Declaration) 
Public Class WorkQueue(Of T) 
   Implements IWorkQueue(Of T) 
C# 
public class WorkQueue<T> : IWorkQueue<T>  

Type Parameters

T

Example

Library/Library.Test/TestWorkQueue.cs

C#Copy Code
int[] counter = new int[1];
using (WorkQueue<int[]> worker = new WorkQueue<int[]>(ProcessOne, Math.Max(2, Environment.ProcessorCount)))
{
    for (int i = 0; i < 1000; i++)
        worker.Enqueue(counter);
    worker.Complete(false, 10);
}
Assert.AreNotEqual(0, counter[0]);
VB.NETCopy Code
Dim counter As Integer() = New Integer(1) {}
Using worker As New WorkQueue(Of Integer())(ProcessOne, Math.Max(2, Environment.ProcessorCount))
    Dim i As Integer = 0
    While i < 1000
        worker.Enqueue(counter)
        System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
    End While
    worker.Complete(False, 10)
End Using
Assert.AreNotEqual(0, counter(0))

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Threading.WorkQueue<T>
      CSharpTest.Net.Threading.WorkQueue

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys